package com.zhiyou.springcloud.eurekaclient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author by zhouyanchao
 * Created on 2018/2/27.
 * Descr: 通过DiscoveryClient对象，在日志中打印出服务实例的相关内容
 */
@RestController
public class DcController {

	@Autowired
	DiscoveryClient discoveryClient;

	@GetMapping("/dc")
	public String dc(){
		System.out.println("dc controller services:");
		String s ="services:"+discoveryClient.getServices();
		System.out.println(s);
		return s;
	}

	/**
	 * 此方法是验证容错机制时测试使用，到调用的时候再回过头来看
	 * @return
	 */
	@GetMapping("/delay")
	public String delay(){
		System.out.println("delay controller services:");

		try {
			//为了验证容错机制，让程序暂停5s，模拟调用超时
			Thread.sleep(5000L);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		String s ="services:"+discoveryClient.getServices();
		System.out.println(s);
		return s;
	}

}
